<template>
  <div id="table_container">
    <el-card style="margin-bottom: 5px; text-align: left">
      <el-input v-model="keyWord" placeholder="输入搜索内容" style="width: 200px;" @keyup.enter.native="handleFilter"></el-input>
      <el-button type="primary" icon="el-icon-search" @click="handleFilter" style="margin-left: 10px;">
        查询
      </el-button>
    </el-card>
    <el-card>
      <el-table
          :data="tableData"
          v-loading="loading"
          row-key="id"
          border>
        <el-table-column
            type="selection"
            align="center"
            width="48">
        </el-table-column>
        <el-table-column
            type="index"
            label="序号"
            align="center"
            width="50">
        </el-table-column>
        <el-table-column
            prop="request_modular"
            label="请求模块">
        </el-table-column>
        <el-table-column
            prop="request_path"
            label="请求路径">
        </el-table-column>
        <el-table-column
            prop="request_method"
            label="请求方法"
            align="center">
        </el-table-column>
        <el-table-column
            prop="request_ip"
            label="请求IP"
            align="center">
        </el-table-column>
        <el-table-column
            prop="request_browser"
            label="浏览器标识"
            align="center">
        </el-table-column>
        <el-table-column
            prop="response_code"
            label="状态码"
            align="center">
        </el-table-column>
        <el-table-column
            prop="response_content"
            label="返回信息"
            align="center">
        </el-table-column>
        <el-table-column
            prop="creator"
            label="操作人"
            align="center">
        </el-table-column>
        <el-table-column
            label="时间"
            align="center"
            width="120">
          <template slot-scope="scope">
            <i class="el-icon-time"></i>
            <span style="margin-left: 10px">{{ scope.row.create_time }}</span>
          </template>
        </el-table-column>
        <el-table-column
            fixed="right"
            align="center"
            label="操作">
          <template slot-scope="scope">
<!--            <el-button @click="handleClick(scope.row)" icon="el-icon-search" circle></el-button>-->
          </template>
        </el-table-column>
      </el-table>
      <pagination
          v-show="pageTotal>0"
          :total="pageTotal"
          :page.sync="page"
          :pageSize.sync="pageSize"
          @pagination="getDataList"/>
    </el-card>
  </div>
</template>

<script>
import {getOperationLog} from "@/api";
import pagination from '@/components/Pagenation'

export default {
  name: "index",
  components: {
    pagination
  },
  data() {
    return {
      tableData: [],
      loading: true,
      keyWord: undefined,

      // 分页器相关
      page: 1,
      pageTotal: 0,
      pageSize: 10,
    }
  },
  mounted() {
    this.getDataList()
  },
  methods: {
    getDataList(params = {}) {
      this.loading = true

      params['page'] = this.page
      params['pageSize'] = this.pageSize
      params['keyWord'] = this.keyWord
      getOperationLog(params).then(res => {
        this.tableData = res.data.results;
        this.pageTotal = res.data.count;
        setTimeout(() => {
          this.loading = false
        }, 1.5 * 500)
      })
    },
    handleFilter() {
      this.getDataList()
    },
  }
}
</script>

<style scoped>

</style>